home *** CD-ROM | disk | FTP | other *** search
/ ADA Programming Guide / ADA Programming Guide.iso / ada_gnu / adainc / s-widllu.adb < prev    next >
Text File  |  1996-01-30  |  3KB  |  68 lines

  1. ------------------------------------------------------------------------------
  2. --                                                                          --
  3. --                         GNAT RUNTIME COMPONENTS                          --
  4. --                                                                          --
  5. --                       S Y S T E M . W I D _ L L U                        --
  6. --                                                                          --
  7. --                                 B o d y                                  --
  8. --                                                                          --
  9. --                            $Revision: 1.4 $                              --
  10. --                                                                          --
  11. --           Copyright (c) 1992,1993,1994 NYU, All Rights Reserved          --
  12. --                                                                          --
  13. -- The GNAT library is free software; you can redistribute it and/or modify --
  14. -- it under terms of the GNU Library General Public License as published by --
  15. -- the Free Software  Foundation; either version 2, or (at your option) any --
  16. -- later version.  The GNAT library is distributed in the hope that it will --
  17. -- be useful, but WITHOUT ANY WARRANTY;  without even  the implied warranty --
  18. -- of MERCHANTABILITY  or  FITNESS FOR  A PARTICULAR PURPOSE.  See the  GNU --
  19. -- Library  General  Public  License for  more  details.  You  should  have --
  20. -- received  a copy of the GNU  Library  General Public License  along with --
  21. -- the GNAT library;  see the file  COPYING.LIB.  If not, write to the Free --
  22. -- Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.        --
  23. --                                                                          --
  24. ------------------------------------------------------------------------------
  25.  
  26. with System.Unsigned_Types; use System.Unsigned_Types;
  27.  
  28. package body System.Wid_LLU is
  29.  
  30.    ------------------------------
  31.    -- Width_Long_Long_Unsigned --
  32.    ------------------------------
  33.  
  34.    function Width_Long_Long_Unsigned
  35.      (Lo, Hi : Long_Long_Unsigned)
  36.       return   Natural
  37.    is
  38.       W : Natural;
  39.       T : Long_Long_Unsigned;
  40.  
  41.    begin
  42.       if Lo > Hi then
  43.          return 0;
  44.  
  45.       else
  46.          --  Minimum value is 2, one for sign, one for digit
  47.  
  48.          W := 2;
  49.  
  50.          --  Get max of absolute values, but avoid bomb if we have the maximum
  51.          --  negative number (note that First + 1 has same digits as First)
  52.  
  53.          T := Long_Long_Unsigned'Max (Lo, Hi);
  54.  
  55.          --  Increase value if more digits required
  56.  
  57.          while T >= 10 loop
  58.             T := T / 10;
  59.             W := W + 1;
  60.          end loop;
  61.  
  62.          return W;
  63.       end if;
  64.  
  65.    end Width_Long_Long_Unsigned;
  66.  
  67. end System.Wid_LLU;
  68.